<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@page isELIgnored="false" %>
<!DOCTYPE>
<html>
<head>
    <title>订单管理</title>
    <link type="text/css" rel="stylesheet" href="/css/bootstrap.css">
    <link href="/css/admin/materialdesignicons.min.css" rel="stylesheet">
    <link href="/css/admin/style.min.css" rel="stylesheet">

    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script type="text/javascript" src="/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="/js/layer.js"></script>

    <script type="text/javascript" src="/js/admin/main.min.js"></script>
    <script type="text/javascript" src="/js/admin/multitabs.js"></script>
</head>
<body>
<br>

<ul class="nav nav-tabs">
    <li <c:if test="${status == 1}">class="active"</c:if>>
        <a href="/bookmall/admin/orders/1?pageNum=1">全部订单</a>
    </li>

    <li <c:if test="${status== 5}">class="active"</c:if>>
        <a href="/bookmall/admin/orders/5?pageNum=1">未付款</a>
    </li>

    <li <c:if test="${status== 2}">class="active"</c:if>>
        <a href="/bookmall/admin/orders/2?pageNum=1">已付款</a>
    </li>

    <li <c:if test="${status== 3}">class="active"</c:if>>
        <a href="/bookmall/admin/orders/3?pageNum=1">配送中</a>
    </li>

    <li <c:if test="${status== 4}">class="active"</c:if>>
        <a href="/bookmall/admin/orders/4?pageNum=1">已完成</a>
    </li>
    <li <c:if test="${status== 6}">class="active"</c:if>>
        <a href="/bookmall/admin/orders/6?pageNum=1">申请退款</a>
    </li>
    <li <c:if test="${status== 0}">class="active"</c:if>>
        <a href="/bookmall/admin/orders/0?pageNum=1">用户已删除订单</a>
    </li>
</ul>

<br>

<div class="table-responsive">
    <table class="table table-hover" style="text-align: center" aria-describedby="orderTable">
        <tr>
            <th style="text-align: center">ID</th>
            <th style="text-align: center">总价</th>
            <th style="text-align: center">商品详情</th>
            <th style="text-align: center">收货信息</th>
            <th style="text-align: center">订单状态</th>
            <th style="text-align: center">支付方式</th>
            <th style="text-align: center">下单用户</th>
            <th style="text-align: center">下单时间</th>
            <th style="text-align: center">操作</th>
        </tr>

        <c:forEach items="${page.list}" var="order">
            <tr>
                <td><p>${order.id }</p></td>
                <td><p>${order.total }</p></td>
                <td>
                    <c:forEach items="${order.itemList}" var="item">
                        <p>${item.book.name}(${item.price}) x ${item.amount}</p>
                    </c:forEach>
                </td>
                <td>
                    <p>${order.realName}</p>
                    <p>${order.phone}</p>
                    <p>${order.address}</p>
                </td>
                <td>
                    <p>
                        <c:if test="${order.status==2}"><span style="color:#33cabb;">已付款</span></c:if>
                        <c:if test="${order.status==3}"><span style="color:green;">已发货</span></c:if>
                        <c:if test="${order.status==4}"><span style="color:black;">已完成</span></c:if>
                        <c:if test="${order.status==5}"><span style="color:red;">未付款</span></c:if>
                        <c:if test="${order.status==6}"><span style="color:red;">申请退款</span></c:if>
                        <c:if test="${order.status==7}"><span style="color:green;">完成退款</span></c:if>
                        <c:if test="${order.status==0}"><span style="color:red;">已完成(用户删除)</span></c:if>
                    </p>
                </td>
                <td>
                    <p>
                        <c:choose>
                            <c:when test="${order.paytype==1}">支付宝</c:when>
                            <c:otherwise>无</c:otherwise>
                        </c:choose>
                    </p>
                </td>
                <td><p>${order.realName}</p></td>
                <td><p><fmt:formatDate value="${order.createTime}" pattern="yyyy-MM-dd HH:mm:ss" /></p></td>
                <td>
                        <%--用户已付款，改为发货状态--%>
                    <c:if test="${order.status==2}">
                        <a class="btn btn-success" href="/bookmall/admin/order/change?id=${order.id}&status=3">发货</a>
                    </c:if>
                    <c:if test="${order.status==6}">
                        <a class="btn btn-success" href="/bookmall/admin/order/change?id=${order.id}&status=7">同意</a>
                    </c:if>

                        <%--针对用户未付款或者已确认收货的订单--%>
                    <c:if test="${order.status==5 || order.status==0 || order.status==7}">
                        <button id="btn_delete" type="button" class="btn btn-danger"
                                onclick="deleteOrder('${order.id}',${status})">
                            <span class="mdi mdi-window-close" aria-hidden="true"></span>删除
                        </button>
                    </c:if>

                </td>
            </tr>
        </c:forEach>
    </table>
</div>


<br>
<c:choose>
    <c:when test="${!empty page.list}">
        <jsp:include page="./pagination.jsp">
            <jsp:param value="bookmall/admin/orders" name="url" />
            <jsp:param value="${status}" name="param" />
        </jsp:include>
    </c:when>

    <c:otherwise>
        <div style='text-align:center; color: #33cabb;'>暂无数据...</div>
    </c:otherwise>
</c:choose>
<br>

<script>
    function deleteOrder(orderId, status) {

        layer.open({
            content: '确 定 要 删 除 编 号 为 : ' + orderId + '  的 订 单  所 有 信 息 吗？',
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                $.get('/bookmall/admin/order/remove/' + orderId, function (data) {
                    if (data) {
                        layer.msg("信息删除成功~", {time: 1500}, function () {
                            window.location.href = "/bookmall/admin/orders/" + status + "?pageNum=1";
                        });
                    } else {
                        layer.msg("信息删除失败！请确认信息是否完整或联系管理员!", {time: 2000}, function () {
                            window.location.href = "/bookmall/admin/orders/1?pageNum=1";
                        });
                    }
                });
            },
            btn2: function (index, layero) {
                layer.msg("已取消操作...", {icon: 2});
            },
            cancel: function () {
                layer.msg("操作已取消...", {icon: 2});
            }
        });
    }
</script>

</body>
</html>
